<?php
/**
 * Created by PhpStorm.
 * User: dy
 * Date: 2020/1/7
 * Time: 14:41
 */
namespace util;
class ConfigUtil
{
    protected static $instance = null;
    private function __construct()
    {
    }
    private function __clone()
    {
    }

    public static function instance(){
        if(empty(self::$instance)){
            self::$instance = new static();
        }
        return self::$instance;
    }

    /**
     * 分析数组及枚举类型配置值 格式 a:名称1,b:名称2
     * @return array
     */
    function parse_config_attr($string)
    {
        $array = preg_split('/[,;\r\n]+/', trim($string, ",;\r\n"));
        if (strpos($string, ':')) {
            $value = [];
            foreach ($array as $val) {
                list($k, $v) = explode(':', $val);
                $value[$k] = $v;
            }
        } else {
            $value = $array;
        }
        return $value;
    }

    /**
     * 解析数组配置
     */
    function parse_config_array($name = '')
    {
        return $this->parse_config_attr($name);
    }
}